package pervasivePositioning.pos;
import android.location.Location;

public class DistanceStrategy extends ReportingStrategy {
	
	float minDist;
	Location lastFix;

	public void setValue(float m) {
		//Value is a minimum distance
		if (m > 0)
			minDist = m;
	}

	public float getValue() {
		return minDist;		
	}

	public DistanceStrategy() {
	}

	public DistanceStrategy(float minDistance) {
		setValue(minDistance);
	}

	@Override
	public boolean reportPosition(Location newloc) {
		if (lastFix == null)
			return true;
		
		float dist = newloc.distanceTo(lastFix);
		
		if (lastFix != null && dist < minDist) {
			return false;
		}
		
		lastFix = newloc;
		return true;
	}

	@Override
	public String getName() {
		return "DistanceStrategy";
	}
	
	@Override
	public String getValueName() {
		return "minDist";
	}	

	@Override
	public String getConfig() {
		return String.valueOf(minDist);
	}

}
